package com.android.bonn.fast

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.android.bonn.fast.adapter.SimpleCellDelegateAdapter
import com.android.bonn.fast.adapter.ext.buildCells
import com.android.bonn.fast.adapter.ext.create
import com.android.bonn.fast.databinding.ActivityMainBinding

class AnyListActivity : AppCompatActivity() {

  private lateinit var mBinding: ActivityMainBinding
  private lateinit var adapter: SimpleCellDelegateAdapter

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    mBinding = ActivityMainBinding.inflate(layoutInflater)
    setContentView(mBinding.root)


    mBinding.testListView.layoutManager = LinearLayoutManager(this)
    adapter = mBinding.testListView
      .buildCells()
      .create(R.layout.item_view_layout, { StringCellView(it) }, { _, item -> item is String })
      .create(R.layout.item_view_layout, { IntCellView(it) }, { _, item -> item is Int })
      .create(R.layout.item_view_layout, { BooleanCellView(it) }, { _, item -> item is Boolean })
      .build()

    mBinding.testListView.adapter = adapter


    adapter.submitList(getTestData())
  }


  private fun getTestData() = mutableListOf<Any>("1", 2, "2", 4, "2", 6, "2", 8, "2", 9, "2", false, true)
}